More...
Go to the source code of this file.
|
|
typedef struct mrb_range_edges | mrb_range_edges |
| | Range class.
|
|
| enum | mrb_range_beg_len { MRB_RANGE_TYPE_MISMATCH = 0
, MRB_RANGE_OK = 1
, MRB_RANGE_OUT = 2
} |
See Copyright Notice in mruby.h
◆ mrb_gc_free_range
| #define mrb_gc_free_range |
( |
| mrb, |
|
|
| p ) |
Value:mrb_free(mrb, (p)->edges)
◆ mrb_range_beg
| #define mrb_range_beg |
( |
| mrb, |
|
|
| r ) |
Value:RANGE_BEG(mrb_range_ptr(mrb, r))
◆ mrb_range_end
| #define mrb_range_end |
( |
| mrb, |
|
|
| r ) |
Value:RANGE_END(mrb_range_ptr(mrb, r))
◆ mrb_range_excl_p
| #define mrb_range_excl_p |
( |
| mrb, |
|
|
| r ) |
Value:RANGE_EXCL(mrb_range_ptr(mrb, r))
◆ mrb_range_raw_ptr
| #define mrb_range_raw_ptr |
( |
| r | ) |
|
◆ mrb_range_value
| #define mrb_range_value |
( |
| p | ) |
|
Value:mrb_obj_value((void*)(p))
◆ RANGE_BEG
◆ RANGE_END
◆ RANGE_EXCL
◆ mrb_range_beg_len()
| enum mrb_range_beg_len mrb_range_beg_len |
( |
mrb_state * | mrb, |
|
|
mrb_value | range, |
|
|
mrb_int * | begp, |
|
|
mrb_int * | lenp, |
|
|
mrb_int | len, |
|
|
mrb_bool | trunc ) |
|
extern |
Calculates the beginning position and length of a range.
This function is typically used to get array offsets. It interprets the range as a sequence of integers.
- If the beginning of the range is nil, it's treated as 0.
- If the end of the range is nil, it's treated as -1 (or the last element).
The function handles negative indices, out-of-bounds conditions, and truncation based on the provided length and trunc flag.
- Parameters
-
| mrb | The mruby state. |
| range | The Range object (mrb_value). |
| [out] | begp | Pointer to store the calculated beginning position. |
| [out] | lenp | Pointer to store the calculated length. |
| len | The length of the sequence the range is being applied to. |
| trunc | If true, truncate the range to fit within the given length. |
- Returns
- An enum mrb_range_beg_len indicating success (MRB_RANGE_OK), type mismatch (MRB_RANGE_TYPE_MISMATCH), or out of bounds (MRB_RANGE_OUT).
◆ mrb_range_new()
Creates a new Range object.
This function allocates and initializes a new Range object with the given beginning and end values, and an exclude_end flag.
- Parameters
-
| mrb | The mruby state. |
| beg | The beginning value of the range. |
| end | The end value of the range. |
| excl | A boolean flag indicating whether the end value is excluded (true) or included (false). |
- Returns
- The new Range object (mrb_value).
◆ mrb_range_ptr()
Retrieves a pointer to the internal RRange structure from a Range object.
This function ensures that the given Range object is properly initialized before returning a pointer to its data. If the Range is not initialized, it raises an E_ARGUMENT_ERROR.
- Parameters
-
| mrb | The mruby state. |
| range | The Range object (mrb_value) from which to get the pointer. |
- Returns
- A pointer to the struct RRange.